package lar.system.network.msgParser;

public class Validation 
{
	public static int NO_SYMBOLS = 1 << 0;
	public static int NO_NUMBERS = 1 << 1;
	public static int CHAR_FIRST = 1 << 2;
	public static int LOWER_CASE = 1 << 3;
	public static int UPPER_CASE = 1 << 4;
	public static int HAS_LETTERS= 1 << 5;
	public static int NO_SPACES  = 1 << 6;
	
	public static boolean validateString(String str, int flags)
	{
		boolean hasletter = false;
		for(int i = 0; i < str.length(); i++)
		{
			char c = str.charAt(i);
			if(((flags & NO_SYMBOLS) != 0) && ((c > 0x5A && c <= 0x60) || (c >= 0x3A && c <= 0x40) || (c > 0x20 && c < 0x30) || (c > 0x7A))) 
				return false;
			if(((flags & NO_NUMBERS) != 0) && (c >= '0' && c <= '9'))
				return false;
			if(((flags & CHAR_FIRST) != 0) && (i == 0) && !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')))
				return false;
			if(((flags & LOWER_CASE) != 0) && (c >= 'A' && c <= 'Z'))
				return false;
			if(((flags & UPPER_CASE) != 0) && (c >= 'a' && c <= 'z'))
				return false;
			if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
				hasletter = true;
			if(((flags & NO_SPACES) != 0) && c == ' ')
				return false;
		}
		if(((flags & HAS_LETTERS) != 0) && !hasletter) return false;
		
		
		return true;
	}
	
	/*
	public static void main(String args[])
	{
		System.out.println(validateString("654 3a", NO_SYMBOLS | NO_SPACES));
	}*/
}
